package ncme.auto.framework.core.services.Impl.base;

import ncme.auto.framework.core.annotation.Remind;
import ncme.auto.framework.core.utils.StringUtil;

import java.util.List;

public abstract class Constants extends StringUtil {

    protected final Class<?> ENTITY_CLASS = getEntityClass();

    protected final String ENTITY_NAME = ENTITY_CLASS.getSimpleName();

    protected final String ENTITY_NAME_LOWER = toLower(ENTITY_NAME);

    protected final List<String> FIELD_NAMES = getFieldNames(ENTITY_CLASS);

    @Remind("由数据库实体中的 @RequiredField 注解标识，标识新增、修改项")
    protected final List<String> REQUIRED_FIELD = getRequiredFields();

    @Remind("由数据库实体中的 @VerifyRepetitionField 注解标识，标识用于单一验重的字段")
    protected final List<String> VERIFY_REPETITION_FIELD = getVerifyRepetitionFields();

    @Remind("由数据库实体中的 @VerifyRepetitionField 注解标识，标识用于组合验重的字段")
    protected final List<String> VERIFY_MULTI_REPETITION_FIELD = getVerifyMultiRepetitionFields();

    //######## mapper BEG########//

    protected final String PRIMARY_FIELD_NAME = getPrimary();

    protected final String SECONDARY_FIELD_NAME = getSecondary();

    //######## mapper END########//

    protected abstract Class<?> getEntityClass();

    protected abstract List<String> getFieldNames(Class<?> entityClass);

    protected abstract List<String> getRequiredFields();

    protected abstract List<String> getVerifyRepetitionFields();

    protected abstract List<String> getVerifyMultiRepetitionFields();

    protected abstract String getPrimary();

    protected abstract String getSecondary();

    public String toLower(String value) {
        return Character.toLowerCase(value.charAt(0)) + value.substring(1);
    }

    public String toUpper(String value) {
        return Character.toUpperCase(value.charAt(0)) + value.substring(1);
    }
}
